# -*- coding: UTF-8 -*- #
# import threading, time

import threading
from time import ctime, sleep
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8') #改变标准输出
class Mythread(threading.Thread):
    def __init__(self, func, args):
        threading.Thread.__init__(self)
        self.func = func
        self.args = args

    def run(self):
        self.func(*self.args)

def loop(num, sleep_time, lock):
    sleep(sleep_time)
    print(num, ": ", ctime())
    lock.release()  # 释放锁

if __name__ == '__main__':
    tuples = (3, 2, 9)
    locks = []
    threads = []
    print("开始:", ctime())
    for i in range(len(tuples)):
        lock = threading.Lock()
        lock.acquire()
        locks.append(lock)
        t = Mythread(loop, (i, tuples[i], locks[i]))
        t.start()
    [t.join() for t in threads]
    # 等待所有锁被释放
    for i in range(len(tuples)):
        while(locks[i].locked()):
            pass
    print('结束', ctime())
